package com.daiTest.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

//创建第一个秘书handlerMapping和经理handlerAdapter的bean
//创建json转化器
@EnableWebMvc
@Configuration
//第一个扫描的包是controller层 第二个扫描的包是全局异常处理器
@ComponentScan({"com.daiTest.Controller", "com.daiTest.exceptionhandler"})

public class MvcConfig implements WebMvcConfigurer {

    //因为上面写了EnableWebMvc注解，所以这两个方法可以不写
//    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
//        return new RequestMappingHandlerMapping();
//    }
//
//    public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
//        return new RequestMappingHandlerAdapter();
//    }

    //创建第二个秘书 打开静态资源处理
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    //混合开发使用的视图解析器

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/views/", ".jsp");
    }


    //拦截器

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(new xx()).addPathPatterns("/**");
    }
}
